﻿<%@ Page Language="C#" MasterPageFile="~/share/MainPage.Master" AutoEventWireup="true"
    CodeBehind="ShoppingCart.aspx.cs" Inherits="AKMII.DMRA.Web.ShoppingCart" Title="Shopping Cart" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="InfoContent" runat="server">
    <script type="text/javascript">
        function DisplayTooltip(value) {
            document.getElementById("divTooltip").style.display = value;
        }
    </script>
    <br />
    <div class="leadinfo" style="position: relative">
        <div>
            You currently have
            <asp:Label ForeColor="Red" ID="lbCartAgent" runat="server" Text="0"></asp:Label>
            active & lapse stops in your cart.<br />
            <br />
            Your total stops so far are:<br />
            <asp:Label ForeColor="Red" ID="lbActiveLead" runat="server" Text="0"></asp:Label>
            Active;<br />
            <asp:Label ForeColor="Red" ID="lbLapseLead" runat="server" Text="0"></asp:Label>
            Lapsed;
            <br />
            <asp:Label ForeColor="Red" ID="lbNeighborLead" runat="server" Text="0"></asp:Label>
            Neighbor;
            <br />
            <asp:Label ForeColor="Red" ID="lbBussinessLead" runat="server" Text="0"></asp:Label>
            Business<br />
        </div>
        <asp:HiddenField ID="lbAllLeads" runat="server" />
        <div id="divTooltip" onmouseout="DisplayTooltip('none');" style="background-color: #E1EEF6;
            position: absolute; top: 15px; display: none; border: 1px #000000 solid; padding-left: 5px">
            Target number of leads are based on active stops plus lapse stops ( neighbor and
            business are not – although you still get them).<br />
            Agents can work on average 50 active & lapse stops per week.<br />
            As an example, an MD has Y amount of agents working under him.<br />
            Therefore (50*num of weeks in the month)*Y=Z (where Z is the target number of leads)<br />
        </div>
    </div>
</asp:Content>
<asp:Content ID="Content4" ContentPlaceHolderID="LinkContent" runat="server">
    <a id="breadcrumb_home" href="#">Home</a>&nbsp;&gt;&nbsp;<a id="A2" href="javascript:void(0);">Shopping
        Cart</a>
</asp:Content>
<asp:Content ID="Content5" ContentPlaceHolderID="DetailsContent" runat="server">
    <script type="text/javascript">
        function $(id) {
            return document.getElementById("ctl00_DetailsContent_" + id);
        }
        function SelectAll() {
            var table = $("GridView1");
            var headbox = document.getElementById("chbHead");
            var checkboxs = table.getElementsByTagName("input");
            for (var i = 0; i < checkboxs.length; i++) {
                if (checkboxs[i].type == "checkbox") {
                    if (headbox.checked) {
                        checkboxs[i].checked = true;
                    }
                    else {
                        checkboxs[i].checked = false;
                    }
                }
            }
            ChangeInfo();
        }

        function ChangeInfo() {
            var table = $("GridView1");
            var hiddenNum = $("hiddenNum");
            var hiddenNum1 = $("hiddenActive");
            var hiddenNum2 = $("hiddenBussiness");
            var hiddenNum3 = $("hiddenLapse");
            var hiddenNum4 = $("hiddenNeighbor");
            var lbneighbor = document.getElementById("ctl00_InfoContent_lbNeighborLead");
            var lbactive = document.getElementById("ctl00_InfoContent_lbActiveLead");
            var lbbussiness = document.getElementById("ctl00_InfoContent_lbBussinessLead");
            var lblapse = document.getElementById("ctl00_InfoContent_lbLapseLead");
            var lbsum = document.getElementById("ctl00_InfoContent_lbCartAgent");
            //var lbremain = document.getElementById("ctl00_InfoContent_lblRemain");
            var lbtotal = document.getElementById("lbTtotal");
            var otherpageSelected = parseInt(hiddenNum.value, 10);
            var otherpageSelected1 = parseInt(hiddenNum1.value, 10);
            var otherpageSelected2 = parseInt(hiddenNum2.value, 10);
            var otherpageSelected3 = parseInt(hiddenNum3.value, 10);
            var otherpageSelected4 = parseInt(hiddenNum4.value, 10);
            var sumactive = 0;
            var sumbussiness = 0;
            var sumlapse = 0;
            var sumneighbor = 0;
            var sum = 0;
            for (var j = 1; j < table.rows.length; j++) {
                var checkboxs = table.rows[j].getElementsByTagName("input");
                for (var i = 0; i < checkboxs.length; i++) {
                    if (checkboxs[i].type == "checkbox" && !checkboxs[i].disabled) {
                        if (checkboxs[i].checked) {
                            if (table.rows[j].cells[14].innerText == "All") {
                                var rowActiveLeads = parseInt(table.rows[j].cells[10].innerHTML, 10);
                                var rowLapseLeads = parseInt(table.rows[j].cells[11].innerHTML, 10);
                                var rowNeighbor = parseInt(table.rows[j].cells[12].innerHTML, 10);
                                sumactive = sumactive + rowActiveLeads;
                                sumlapse = sumlapse + rowLapseLeads;
                                sumneighbor = sumneighbor + rowNeighbor;
                                sum = sum + rowActiveLeads + rowLapseLeads;
                                var rowBussiness = parseInt(table.rows[j].cells[13].innerHTML, 10);
                                sumbussiness = sumbussiness + rowBussiness;
                            }
                            else if (table.rows[j].cells[14].innerText == "ALN") {
                                var rowActiveLeads = parseInt(table.rows[j].cells[10].innerHTML, 10);
                                var rowLapseLeads = parseInt(table.rows[j].cells[11].innerHTML, 10);
                                var rowNeighbor = parseInt(table.rows[j].cells[12].innerHTML, 10);
                                sumactive = sumactive + rowActiveLeads;
                                sumlapse = sumlapse + rowLapseLeads;
                                sumneighbor = sumneighbor + rowNeighbor;
                                sum = sum + rowActiveLeads + rowLapseLeads;
                            }
                            else {
                                var rowBussiness = parseInt(table.rows[j].cells[13].innerHTML, 10);
                                sumbussiness = sumbussiness + rowBussiness;
                            }
                        }
                    }
                }
            }
            lbneighbor.innerHTML = sumneighbor + otherpageSelected4;
            lbactive.innerHTML = sumactive + otherpageSelected1;
            lbbussiness.innerHTML = sumbussiness + otherpageSelected2;
            lblapse.innerHTML = sumlapse + otherpageSelected3;
            //lbsum.innerHTML=sum+otherpageSelected;
            //lbremain.innerHTML = (parseInt(lbtotal.innerHTML, 10) - sum - otherpageSelected).toString();
        }

        function CheckSelected() {
            var table = $("GridView1");
            if (table != null) {
                var sum = 0;
                var hiddenNum = $("hiddenUnselectedNum");
                var otherpageSelected = parseInt(hiddenNum.value, 10);
                var sumBusiness = 0;
                //var checknull=0;
                if (table.rows.length <= 1) {
                    alert("There is no record for refresh!");
                    return false;
                }
                for (var j = 1; j < table.rows.length; j++) {
                    var checkboxs = table.rows[j].getElementsByTagName("input");
                    for (var i = 0; i < checkboxs.length; i++) {
                        if (checkboxs[i].type == "checkbox" && !checkboxs[i].disabled) {
                            if (!checkboxs[i].checked) {
                                if (table.rows[j].cells[14].innerText == "All") {
                                    var rowActiveLeads = parseInt(table.rows[j].cells[10].innerHTML, 10);
                                    var rowLapseLeads = parseInt(table.rows[j].cells[11].innerHTML, 10);
                                    var rowNeighbor = parseInt(table.rows[j].cells[12].innerHTML, 10);
                                    sum = sum + rowActiveLeads + rowLapseLeads;
                                    var rowBussiness = parseInt(table.rows[j].cells[13].innerHTML, 10);
                                    sumBusiness = sumBusiness + rowBussiness;
                                }
                                else if (table.rows[j].cells[14].innerText == "ALN") {
                                    var rowActiveLeads = parseInt(table.rows[j].cells[10].innerHTML, 10);
                                    var rowLapseLeads = parseInt(table.rows[j].cells[11].innerHTML, 10);
                                    var rowNeighbor = parseInt(table.rows[j].cells[12].innerHTML, 10);
                                    sum = sum + rowActiveLeads + rowLapseLeads;
                                }
                                else {
                                    var rowBussiness = parseInt(table.rows[j].cells[13].innerHTML, 10);
                                    sumBusiness = sumBusiness + rowBussiness;
                                }
                                //checknull=checknull+rowActiveLeads+rowLapseLeads+rowBussiness+rowNeighbor;
                            }
                        }
                    }
                }

                if (!confirm("You are about to remove " + (sum + otherpageSelected) + " active & lapse contacts and " + sumBusiness + " business contacts to your cart. Did you want to do that?")) {
                    return false;
                }
            }
            else {
                return false;
            }
        }

        function CheckSelected1() {
            var table = $("GridView1");
            if (table != null) {
                if (table.rows.length <= 1) {
                    alert("There is no record for order!");
                    return false;
                }
                var sum = 0;
                var hiddenNum = $("hiddenNum");
                var estimateLead = parseInt($("hiddenEstimate").value, 10);
                var otherpageSelected = parseInt(hiddenNum.value, 10);
                var sumBusiness = 0;
                //var checknull=0;
                for (var j = 1; j < table.rows.length; j++) {
                    var checkboxs = table.rows[j].getElementsByTagName("input");
                    for (var i = 0; i < checkboxs.length; i++) {
                        if (checkboxs[i].type == "checkbox" && !checkboxs[i].disabled) {
                            if (checkboxs[i].checked) {
                                if (table.rows[j].cells[14].innerText == "All") {
                                    var rowActiveLeads = parseInt(table.rows[j].cells[10].innerHTML, 10);
                                    var rowLapseLeads = parseInt(table.rows[j].cells[11].innerHTML, 10);
                                    var rowNeighbor = parseInt(table.rows[j].cells[12].innerHTML, 10);
                                    sum = sum + rowActiveLeads + rowLapseLeads;
                                    var rowBussiness = parseInt(table.rows[j].cells[13].innerHTML, 10);
                                    sumBusiness = rowBussiness + sumBusiness;
                                }
                                else if (table.rows[j].cells[14].innerText == "ALN") {
                                    var rowActiveLeads = parseInt(table.rows[j].cells[10].innerHTML, 10);
                                    var rowLapseLeads = parseInt(table.rows[j].cells[11].innerHTML, 10);
                                    var rowNeighbor = parseInt(table.rows[j].cells[12].innerHTML, 10);
                                    sum = sum + rowActiveLeads + rowLapseLeads;
                                }
                                else {
                                    var rowBussiness = parseInt(table.rows[j].cells[13].innerHTML, 10);
                                    sumBusiness = rowBussiness + sumBusiness;
                                }
                            }
                        }
                    }
                }

                if (!confirm("You are about to place an order for " + (sum + otherpageSelected) + " active & lapse contacts and " + sumBusiness + " business contacts. Your active & lapse contacts estimate is " + estimateLead + ". You can only place one order per month. Are you sure you are ready to order?")) {
                    return false;
                }
            }
            else {
                return false;
            }
            return (confirm("We want to make sure you mean to place this order. This is your final order for the period and it can not be changed after this point. Are you sure you are ready to place this order now?"));
        }

        window.onload = function ConsistentCheckbox() {
            var isOrder = $("hiddenIsOrder").value;
            var btnRefresh = $("btnRefresh");
            var btnOrder = $("btnOrder");
            var table = $("GridView1");
            if (isOrder == "1") {
                btnRefresh.disabled = true;
                btnOrder.disabled = true;
                if (table != null) {
                    var headbox = document.getElementById("chbHead");
                    for (var j = 0; j < table.rows.length; j++) {
                        var checkboxs = table.rows[j].getElementsByTagName("input");
                        for (var i = 0; i < checkboxs.length; i++) {
                            if (checkboxs[i].type == "checkbox" && !checkboxs[i].disabled) {
                                checkboxs[i].disabled = true;
                                checkboxs[i].checked = false;
                            }
                        }
                    }
                    if (headbox != null) {
                        headbox.disabled = true;
                    }
                }
            }
            if (table != null) {
                var headbox = document.getElementById("chbHead");
                for (var j = 1; j < table.rows.length; j++) {
                    var checkboxs = table.rows[j].getElementsByTagName("input");
                    for (var i = 0; i < checkboxs.length; i++) {
                        if (checkboxs[i].type == "checkbox" && !checkboxs[i].disabled) {
                            if (checkboxs[i].checked) {
                                return;
                            }
                        }
                    }
                }
                if (headbox != null) {
                    headbox.checked = false;
                }
            }

        }
    </script>
    <div class="addmd" style="padding-bottom: 15px">
        <asp:Button OnClientClick="return CheckSelected();" ID="btnRefresh" CssClass="loginbuttonBtn"
            runat="server" Text="Refresh" OnClick="btnRefresh_Click" />
        &nbsp;&nbsp;&nbsp;&nbsp;
        <asp:Button ID="btnOrder" CssClass="loginbuttonBtn" runat="server" Text="Order Now"
            OnClientClick="return CheckSelected1();" OnClick="btnOrder_Click" />
        &nbsp;&nbsp;&nbsp;&nbsp;
        <input id="btnShopping" type="button" class="loginbuttonBtn" value="Continue Shopping"
            onclick="window.location.href='OrderMap.aspx'" />
        <asp:HiddenField ID="hiddenNum" runat="server" />
        <asp:HiddenField ID="hiddenUnselectedNum" runat="server" />
        <asp:HiddenField ID="hiddenActive" runat="server" />
        <asp:HiddenField ID="hiddenBussiness" runat="server" />
        <asp:HiddenField ID="hiddenLapse" runat="server" />
        <asp:HiddenField ID="hiddenNeighbor" runat="server" />
        <asp:HiddenField ID="hiddenEstimate" runat="server" />
        <asp:HiddenField ID="hiddenIsOrder" runat="server" />
    </div>
    <div id="contentContainnerDiv" class="contentContainnerDiv">
        <asp:GridView ID="GridView1" AllowPaging="True" PageSize="100" runat="server" Width="98%"
            AutoGenerateColumns="False" OnPageIndexChanging="GridView1_PageIndexChanging"
            DataKeyNames="Type" EnableModelValidation="True" 
            onrowdatabound="GridView1_RowDataBound">
            <HeaderStyle CssClass="ItemListHeaderRow" BorderWidth="1px" />
            <Columns>
                <asp:TemplateField>
                    <ItemStyle CssClass="subheader" />
                    <HeaderStyle CssClass="BorderLeft22" />
                    <HeaderTemplate>
                        <input type="checkbox" id="chbHead" checked="checked" onclick="SelectAll();" />
                    </HeaderTemplate>
                    <ItemTemplate>
                        <asp:CheckBox ID="chbItem" Checked="true" runat="server" />
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:BoundField HeaderText="Zip Code" HeaderStyle-CssClass="BorderLeft22" ItemStyle-CssClass="subheader"
                    DataField="ZipName">
                    <HeaderStyle CssClass="BorderLeft22"></HeaderStyle>
                    <ItemStyle CssClass="subheader"></ItemStyle>
                </asp:BoundField>
                <asp:BoundField HeaderText="County" HeaderStyle-CssClass="BorderLeft22" ItemStyle-CssClass="subheader"
                    DataField="County">
                    <HeaderStyle CssClass="BorderLeft22"></HeaderStyle>
                    <ItemStyle CssClass="subheader"></ItemStyle>
                </asp:BoundField>
                <asp:BoundField HeaderText="State" HeaderStyle-CssClass="BorderLeft22" ItemStyle-CssClass="subheader"
                    DataField="State">
                    <HeaderStyle CssClass="BorderLeft22"></HeaderStyle>
                    <ItemStyle CssClass="subheader"></ItemStyle>
                </asp:BoundField>
                <asp:BoundField HeaderText="Preferred City" HeaderStyle-CssClass="BorderLeft22" ItemStyle-CssClass="subheader"
                    DataField="City">
                    <HeaderStyle CssClass="BorderLeft22"></HeaderStyle>
                    <ItemStyle CssClass="subheader"></ItemStyle>
                </asp:BoundField>
                <asp:BoundField HeaderText="Alternate City" HeaderStyle-CssClass="BorderLeft22" ItemStyle-CssClass="subheader"
                    DataField="SecondaryCity">
                    <HeaderStyle CssClass="BorderLeft22"></HeaderStyle>
                    <ItemStyle CssClass="subheader"></ItemStyle>
                </asp:BoundField>
                <asp:BoundField HeaderText="Division" HeaderStyle-CssClass="BorderLeft22" ItemStyle-CssClass="subheader"
                    DataField="Division">
                    <HeaderStyle CssClass="BorderLeft22"></HeaderStyle>
                    <ItemStyle CssClass="subheader"></ItemStyle>
                </asp:BoundField>
                <asp:BoundField HeaderText="Market" HeaderStyle-CssClass="BorderLeft22" ItemStyle-CssClass="subheader"
                    DataField="Market">
                    <HeaderStyle CssClass="BorderLeft22"></HeaderStyle>
                    <ItemStyle CssClass="subheader"></ItemStyle>
                </asp:BoundField>
                <%--<asp:BoundField HeaderText="Terr" HeaderStyle-CssClass="BorderLeft22" ItemStyle-CssClass="subheader"
                    DataField="Territory">
                    <HeaderStyle CssClass="BorderLeft22"></HeaderStyle>
                    <ItemStyle CssClass="subheader"></ItemStyle>
                </asp:BoundField>--%>
                <asp:TemplateField HeaderText="Agent">
                    <EditItemTemplate>
                        <asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("UserAssigned") %>'></asp:TextBox>
                    </EditItemTemplate>
                    <ItemTemplate>
                        <asp:Label ID="lblAgent" runat="server" Text='<%# Bind("UserAssigned") %>'></asp:Label>
                    </ItemTemplate>
                    <HeaderStyle CssClass="BorderLeft22"></HeaderStyle>
                    <ItemStyle CssClass="subheader"></ItemStyle>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="Week">
                    <EditItemTemplate>
                        <asp:TextBox ID="TextBox2" runat="server" Text='<%# Bind("UserAssigned") %>'></asp:TextBox>
                    </EditItemTemplate>
                    <ItemTemplate>
                        <asp:Label ID="lblWeek" runat="server" Text='<%# Bind("UserAssigned") %>'></asp:Label>
                    </ItemTemplate>
                    <HeaderStyle CssClass="BorderLeft22"></HeaderStyle>
                    <ItemStyle CssClass="subheader"></ItemStyle>
                </asp:TemplateField>
                <asp:BoundField HeaderText="Active<br />Count" HtmlEncode="false" HeaderStyle-CssClass="BorderLeft22"
                    ItemStyle-CssClass="subheader" DataField="ActiveLeadCount">
                    <HeaderStyle CssClass="BorderLeft22"></HeaderStyle>
                    <ItemStyle CssClass="subheader"></ItemStyle>
                </asp:BoundField>
                <asp:BoundField HeaderText="Lapsed<br />Count" HtmlEncode="false" HeaderStyle-CssClass="BorderLeft22"
                    ItemStyle-CssClass="subheader" DataField="LapsedLeadCount">
                    <HeaderStyle CssClass="BorderLeft22"></HeaderStyle>
                    <ItemStyle CssClass="subheader"></ItemStyle>
                </asp:BoundField>
                <asp:BoundField HeaderText="Neighbor<br />Count" HtmlEncode="false" HeaderStyle-CssClass="BorderLeft22"
                    ItemStyle-CssClass="subheader" DataField="NeighborLeadCount">
                    <HeaderStyle CssClass="BorderLeft22"></HeaderStyle>
                    <ItemStyle CssClass="subheader"></ItemStyle>
                </asp:BoundField>
                <asp:BoundField HeaderText="Business<br />Count" HtmlEncode="false" HeaderStyle-CssClass="BorderLeft22"
                    ItemStyle-CssClass="subheader" DataField="BusinessLeadCount">
                    <HeaderStyle CssClass="BorderLeft22"></HeaderStyle>
                    <ItemStyle CssClass="subheader"></ItemStyle>
                </asp:BoundField>
                <asp:BoundField DataField="Type">
                    <ControlStyle CssClass="hidden" />
                    <FooterStyle CssClass="hidden" />
                    <HeaderStyle CssClass="hidden" />
                    <ItemStyle CssClass="hidden" />
                </asp:BoundField>
            </Columns>
            <EmptyDataTemplate>
                <table class="leadtable" cellspacing="0" rules="all" border="1" id="ctl00_DetailsContent_GridView1"
                    style="width: 100%;">
                    <tr class="ItemListHeaderRow">
                        <th class="BorderLeft22">
                            Zip Code
                        </th>
                        <th class="BorderLeft22">
                            County
                        </th>
                        <th class="BorderLeft22">
                            State
                        </th>
                        <th class="BorderLeft22">
                            Preferred City
                        </th>
                        <th class="BorderLeft22">
                            Alternate City
                        </th>
                        <th class="BorderLeft22">
                            Division
                        </th>
                        <th class="BorderLeft22">
                            Market
                        </th>
                       <%-- <th class="BorderLeft22">
                            Terr
                        </th>--%>
                        <th class="BorderLeft22">
                            Active<br />
                            Count
                        </th>
                        <th class="BorderLeft22">
                            Lapsed<br />
                            Count
                        </th>
                        <th class="BorderLeft22">
                            Business<br />
                            Count
                        </th>
                        <th class="BorderLeft22">
                            Neighbor<br />
                            Count
                        </th>
                    </tr>
                    <tr>
                        <td class="subheader" colspan="25">
                            There is no record!
                        </td>
                    </tr>
                </table>
            </EmptyDataTemplate>
        </asp:GridView>
    </div>
</asp:Content>
